home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / GZCOLOR.H < prev    next >
C/C++ Source or Header  |  1992-02-16  |  6KB  |  136 lines

  1. /* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gzcolor.h */
  21. /* Private definition of color representation for Ghostscript */
  22. #include "gscolor.h"            /* client interface */
  23.  
  24. /* Colors as seen by clients. */
  25. /* The color parameters are stored internally as color_params. */
  26. typedef unsigned short color_param;
  27. /*
  28.  * The following line should read:
  29.  *    #define max_color_param max_ushort
  30.  * but this seems to trigger brain-damage in a number of compilers.
  31.  * The problems all seem to come up when the compiler has to cast this value
  32.  * to some other type, so we define all the relevant casted values explicitly:
  33.  */
  34. #define max_color_param ((ushort)0xffff)
  35. #define max_color_param_long 0xffffL
  36. #define max_color_param_float ((float)0xffffL)
  37. /* Color_param_bits must be between 8 and 16. */
  38. #define color_param_bits 16
  39. /* Convert a byte to or from a color_param efficiently. */
  40. #define color_param_from_byte(b)\
  41.   (((ushort)(b) << (color_param_bits - 8)) + ((b) >> (16 - color_param_bits)))
  42. #define color_param_to_byte(p)\
  43.   ((p) >> (color_param_bits - 8))
  44.  
  45. /*
  46.  * The following members are used in the structure, depending on the space:
  47.  *    DeviceGray    red, green, blue (all equal)
  48.  *    DeviceRGB    red, green, blue
  49.  *    DeviceCMYK    red, green, blue, not_black
  50.  * luminance is also used for all of the above.
  51.  */
  52. /*typedef struct gs_color_s gs_color;*/    /* in gscolor.h */
  53. struct gs_color_s {
  54.     color_param red, green, blue;    /* RGB/~CMY */
  55.     color_param not_black;        /* ~K */
  56.     color_param luminance;        /* computed luminance */
  57.     byte /*gs_color_space*/ space;    /* see above */
  58.     unsigned is_gray : 1;        /* quick test for gray */
  59.                     /* (red==green==blue) */
  60.     unsigned unused : 6;
  61.     unsigned luminance_set : 1;    /* true if luminance is set */
  62. };
  63. extern color_param gx_color_luminance(P1(struct gs_color_s *));
  64. #define color_luminance(pcolor)\
  65.     ((pcolor)->luminance_set ? (pcolor)->luminance :\
  66.      gx_color_luminance(pcolor))
  67.  
  68. /* Color weights in 100ths, used for computing luminance. */
  69. #define lum_red_weight    30
  70. #define lum_green_weight    59
  71. #define lum_blue_weight    11
  72. #define lum_all_weights    (lum_red_weight + lum_green_weight + lum_blue_weight)
  73.  
  74. /*
  75.  * The following parameters are computed from the above,
  76.  * and kept current through changes in transfer function or device.
  77.  * If the halftone is a colored tile, color1 == color2 == gx_no_color_index,
  78.  * and halftone_level == -1.  (Colored tiles are not currently used.)
  79.  */
  80. typedef struct gx_device_color_s gx_device_color;
  81. struct gx_device_color_s {
  82.     gx_color_index color1;        /* device color, or */
  83.                     /* darker color for halftoning */
  84.     gx_color_index color2;        /* lighter color for halftoning */
  85.     int halftone_level;        /* number of spots to whiten */
  86.                     /* when halftoning, 0 if */
  87.                     /* halftoning not needed, */
  88.                     /* <0 if color halftone */
  89.     struct gx_bitmap_s *tile;    /* pointer to cached halftone */
  90. };
  91. #define color_is_pure(pdevc)\
  92.   ((pdevc)->halftone_level == 0)
  93. #define color_is_color_halftone(pdevc)\
  94.   ((pdevc)->halftone_level < 0)
  95.  
  96. /* A fast version of gz_fill_rectangle. */
  97. /* Note that it takes additional arguments. */
  98. #define gz_fill_rectangle_open(dev, xi, yi, w, h, fill_proc, tile_proc, pdevc, pgs)\
  99.   (color_is_pure(pdevc) ?\
  100.     (*fill_proc)(dev, xi, yi, w, h, pdevc->color1) :\
  101.     (*tile_proc)(dev, pdevc->tile, xi, yi, w, h,\
  102.     pdevc->color1, pdevc->color2,\
  103.     pgs->phase_mod.x, pgs->phase_mod.y) )
  104.  
  105. /* Procedures in gxcolor.c used elsewhere. */
  106. void    gx_set_gray_only(P2(gs_color *, color_param)),
  107.     gx_set_rgb_only(P4(gs_color *, color_param, color_param, color_param));
  108. color_param    gx_color_unit_param(P1(floatp));
  109.  
  110. /* A color transfer function and cache. */
  111. /* log2... must not be greater than color_param_bits. */
  112. #define log2_transfer_map_size 8
  113. #define transfer_map_size (1 << log2_transfer_map_size)
  114. typedef struct gx_transfer_map_s {
  115.     gs_transfer_proc proc;
  116.     color_param values[transfer_map_size];
  117. } gx_transfer_map;
  118. typedef struct gx_transfer_s {
  119.     int ref_count;            /* # of references from gstates */
  120.     gx_transfer_map red, green, blue, gray;
  121. } gx_transfer;
  122.  
  123. /* Map a color_param or byte through a transfer map. */
  124. extern color_param gx_color_param_map(P2(color_param, color_param *));
  125. #define gx_map_color_param(pgs,cp,m)\
  126.   gx_color_param_map(cp, &pgs->transfer->m.values[0])
  127. #if log2_transfer_map_size <= 8
  128. #  define byte_to_tmx(b) ((b) >> (8 - log2_transfer_map_size))
  129. #else
  130. #  define byte_to_tmx(b)\
  131.     (((b) << (log2_transfer_map_size - 8)) +\
  132.      ((b) >> (16 - log2_transfer_map_size)))
  133. #endif
  134. #define gx_map_color_param_byte(pgs,b,m)\
  135.  (pgs->transfer->m.values[byte_to_tmx(b)])
  136.